package com.lihh.rocket5.normal;

import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.exception.RemotingException;

public class DelayProducer {
  public static void main(String[] args) throws MQClientException, MQBrokerException, RemotingException, InterruptedException {
    // 进行 producer 实例化
    DefaultMQProducer producer = new DefaultMQProducer("producer_group_006");
    // 设置name server
    producer.setNamesrvAddr("localhost:9876");
    // 开启 producer
    producer.start();
    
    for (int i = 0; i < 10; i++) {
      String message = String.format("delay producer: %s", (i + 1));
      Message msg = new Message("order006", message.getBytes());
      // 设置延迟等级
      msg.setDelayTimeLevel(4);
      // 可以直接设置时间
//      msg.setDelayTimeMs(1000);
      SendResult result = producer.send(msg);
      System.out.println(result);
    }
  }
}
